home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / BX2BY.HDR < prev    next >
Text File  |  1994-04-25  |  5KB  |  144 lines

  1. /******************************************************************************
  2.                  The Klipper Library, for CA-Clipper 5.x
  3.         Copyright (c), 1994, Wallace Information Systems Engineering
  4.  
  5. FUNCTION:
  6.  
  7. _BaseX2BaseY( cXNum, nXBase, nYBase ) --> cNumStr
  8.  
  9. PARAMETERS:
  10.  
  11. cXNum  : string representation of any number in base 1...72
  12. nXBase : number indicating base of cXNum
  13. nYBase : Base to convert cXNum into
  14.  
  15. SHORT:
  16.  
  17. Convert a number of any base 1...72 to any other base 1...72.
  18.  
  19. DESCRIPTION:
  20.  
  21. _BaseX2BaseY() accepts any number of any base between 1 and 72 in
  22. STRING format (for obvious reasons with HEX (base 16) and greater)
  23. and converts it to the base specified in nYBase.
  24.  
  25. The most common bases numbering systems are:
  26.  
  27. Base 16 (Hexadecimal)
  28. Base 10 (Decimal - our favourite!)
  29. Base 8  (Octal)
  30. Base 2  (Binary - our computer's favourite!)
  31.  
  32.  
  33. But there ARE other number systems.  In fact, any number for which you
  34. have that many unique symbols to represent values can be used as a base.
  35.  
  36. With the IBM PC, we have 256 unique symbols, making possible a base 256
  37. numbering system.  (What you might use that for is beyond me, but it is
  38. possible).  For simplicity, this function supports only base 1 through 72
  39. (approximately the number of printable, NORMAL, everyday English language
  40. characters available from the ascii set).
  41.  
  42. Hexadecimal uses the digits 0-9 and A-F, for a total of 16 unique symbols.
  43. Thus: base 16.
  44.  
  45. Vegisimal uses 20 unique characters and thus: Base 20.  This number system
  46. is purported to have been used by the ancient Mayan Indians.
  47.  
  48. NOTE:
  49.  
  50. NO ERROR CHECKING IS DONE TO ENSURE THAT THE CHARACTERS IN YOUR BASE
  51. NUMBER ARE VALID FOR THE GIVEN BASE!  ERROR CHECKING IS SACRIFICED FOR SAKE
  52. OF SPEED, AND IT IS ASSUMED THAT YOU KNOW WHAT YOU ARE DOING!  YOU SHOULD
  53. KNOW OR CHECK THE VALIDITY OF THE SYMBOLS IN YOUR SOURCE BASE NUMBER!
  54.  
  55. USE CAUTION:  FFGh will be considered a perfectly acceptable
  56. HEXadecimal number with "G" having the decimal equivalent of 16, even
  57. though there is no "G" in the Hexadecimal symbol set!!!
  58.  
  59. Likewise, in FGFh, the "G" will have the decimal equivelent of 289d,
  60. even though the maximum positional value in that place is 256d!!!
  61.  
  62. 8o will be considered a perfectly acceptable Octal number with a value of
  63. 8 even though there IS NO "8" in the Octal symbol set!!!
  64.  
  65. 1102b will be considered a perfectly acceptable Binary number with the
  66. "2" having a value of 2 even though there is no "2" in the Binary
  67. symbol set!!!
  68.  
  69. Who knows?  Maybe this has an interesting application?
  70.  
  71. As far as MAXIMUM values goes, I can only say that when either the number
  72. being converted or the resulting number exceed the capacity of the computer's
  73. 16 digits of base 10 equivelent, you will get unpredictable results.  This is
  74. because the computer/compiler, unlike the human mind, must do it's math in
  75. BASE 10.  Thus, an intermediate Base 10 conversion step is necessary!  When
  76. either the source or target number exceeds the capacity of it's base 10
  77. equivelent, this intermediate step fails and throws off the resulting base
  78. (n) number.
  79.  
  80. Go figure!
  81.  
  82. Remember that the value coming back will always be a STRING representation
  83. of the number.  If you are deriving a DECIMAL value from some other base,
  84. you can convert it to numeric with VAL().
  85.  
  86.  
  87. BE CAREFUL WITH THESE - YOU CAN GET SOME STRANGE RESULTS IF YOU DON'T
  88. CHECK YOU SYMBOLS CAREFULLY!  IT CAN GET REALLY SCAREY ONCE YOU GET UP
  89. INTO BASE 50 OR SO, WHERE ALL KINDS OF CHARACTERS ARE LEGAL!
  90.  
  91. IF YOU COME UP WITH AN INTERESTING APPLICATION FOR NUMBERS IN BASES
  92. HIGHER THAN 16, PLEASE LET ME KNOW!  I'D LOVE TO SEE IT!
  93.  
  94. The _LineEdit???() functions use this function for indexing the comment
  95. databases.  It uses Base 26.  Check out the source code to those functions to
  96. see an example of this function in action with base greater than 16.
  97.  
  98. EXAMPLE:
  99.  
  100. #define VEG  20
  101. #define HEX  16
  102. #define DEC  10
  103. #define OCT  8
  104. #define QUAD 4
  105. #define TRI  3
  106. #define BIN  2
  107.  
  108. t = _BaseX2BaseY('FFFF',HEX,DEC) // "65535"
  109. t = _BaseX2BaseY('FFFF',HEX,OCT) // "177777"
  110. t = _BaseX2BaseY('FFFF',HEX,BIN) // "1111111111111111"
  111. t = _BaseX2BaseY('1101',BIN,DEC) // "13"
  112. t = _BaseX2BaseY('1101',BIN,HEX) // "D"
  113. t = _BaseX2BaseY('1201210',TRI,DEC)  // "1263"
  114. t = _BaseX2BaseY('598',DEC,TRI)  // "211011"
  115. t = _BaseX2BaseY('1032231',QUAD,DEC)  // "5037"
  116. t = _BaseX2BaseY('599',DEC,QUAD)  // "21113"
  117. t = _BaseX2BaseY('120',TRI,BIN)  // "1111"
  118.  
  119. // in base 3 120 = (1*9)+(2*3)+(0*1) = 1111b = 15d = Fh
  120.  
  121. Here are some examples of results obtained with "illegal" character sets!
  122.  
  123. t = _BaseX2BaseY('FFG',HEX,DEC) // "4096"
  124. // FFFh = 4095d  thus, theoritically, FFGh = 4096d even
  125. // though this is illegal!
  126.  
  127.  
  128. t = _BaseX2BaseY('678',OCT,DEC)  // 448
  129. // 677o = 447d, ... same as above!
  130.  
  131.  
  132. t = _BaseX2BaseY('1101',BIN,DEC)  // 13
  133. // this one is OK
  134.  
  135.  
  136. t = _BaseX2BaseY('1102',BIN,DEC)  // 14
  137. // this one same rules as above.  The "2" is taken to mean 2
  138. // even though it is an illegal character!
  139.  
  140. You can really have some fun with this function!  I had a hell of a time
  141. writting it. :-)
  142.  
  143. ******************************************************************************/
  144.